<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>

<script>
    const obj = {
        age: 19
    }

    const p = new Proxy(obj, {
        get(target, key) {
            return target[key];
        },
        set(target, key, val) {
            if (key === 'name' && typeof key === 'string') {
                target[key] = val;
            } else {
                throw new Error("error");
            }
            
        },
        deleteProperty(target, key) {
            delete target[key];
        },
        has(target, key) {
            return key in target;
        },
        apply: function(target, thisArg, arr) {
            return target.apply(thisARg, argArr);
        },
    });
    p.name = 'mr.z'
    delete p.name;
    console.log("name" in p);
    console.log(p) // 我们这里打印代理对象


setTimeout(() => {ee.emit('foobar', () => {console.log("Hello")})}, 1000);
let [value] = await once(ee, 'foobar');
console.log(value);

function once(ee, name) {
    return new Promise((resolve, reject) => {
        ee.on(name)
        resolve()
    })
}

</script>

</html>